﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;

namespace RooHui.Infrastructure.Entities.Repository
{
    [Table("P_ProjectPolicy")]
    public class P_ProjectPolicy : IEntity<P_ProjectPolicy>
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ID { get; set; }
        public int PolicyId { get; set; }
        public int ProjectId { get; set; }

        public override P_ProjectPolicy Find(string key)
        {
            int Id = Int32.Parse(key);
            return Find(c => c.ID == Id);
        }

        public override P_ProjectPolicy Find(System.Linq.Expressions.Expression<Func<P_ProjectPolicy, bool>> where)
        {
            using (Context ctx = new Context())
            {
                var item = ctx.ProjectPolicy.FirstOrDefault(where);
                if (item != null)
                {
                    this.ID = item.ID;
                    this.PolicyId = item.PolicyId;
                    this.ProjectId = item.ProjectId;
                    return this;
                }
                return null;
            }
        }

        public override bool Any(System.Linq.Expressions.Expression<Func<P_ProjectPolicy, bool>> where)
        {
            using (Context ctx = new Context())
            {
                return ctx.ProjectPolicy.Any(where);
            }
        }
    }
}